#include "../Include/Animation.h"


void Animation::Update( FLOAT dt )
{
	// Only do update if we're playing
	if ( m_status != PLAYING )
		return;

	if ( m_elapsedTime > m_spf )
	{
		++m_currFrame;
		m_elapsedTime = 0.0f;

		if ( m_currFrame == m_frames.GetSize() )
		{
			m_currFrame = 0;

			// Check if we're looping or playing once
			switch( m_playType )
			{
			case PLAY_ONCE:
				Stop();
				break;
			case PLAY_LOOPING:
				// Do nothing let it wrap around then continue playing
				break;
			}
		}
	}

	m_elapsedTime += dt;
}

void Animation::AddFrame( Bitmap *pBitmap )
{
	AnimFrame *pAF = new AnimFrame( pBitmap );
	PSX_ThrowAssert( pAF, "Failed to allocated new memory." );
	AddFrame( pAF );

	m_height = pBitmap->GetHeight();
	m_width = pBitmap->GetWidth();
}
